Repository navigation
Conversation
…PredictEnd` and `hooksRaise` The batch path composed only part of the per-call hook surface, and type-checked while doing it: ```ts // Router.predict, ~582 const active = composeHooks(this.hooks, opts.hooks, opts.onPredictStart, opts.onPredictEnd); const raiseErrors = opts.hooksRaise ?? this.hooksRaise; // Router.predictBatch, ~765 (before) const active = composeHooks(this.hooks, opts.hooks); const raiseErrors = this.hooksRaise; ``` So a per-call `onPredictStart` or `onPredictEnd` passed to `predictBatch` was **silently dropped** — no hook, no error — and a per-call `hooksRaise: false` had no effect. `predictMany` forwarded `opts` faithfully to `predictBatch` and so inherited the same gap. Reported in NandhaKishorM#935. The Python side of the same asymmetry was closed in NandhaKishorM#912, which is what makes this a mirror rather than a redesign. ## The fix `PredictBatchOptions` gains the three fields, and the batch dispatch site composes them the way `predict` does — per-call callbacks after per-call `hooks`, both after the installed ones — with `hooksRaise` overriding the router-level flag for that call only. Deliberate choices tested: - **The type grows with the behaviour.** The reason this went unnoticed is that the options interface and the composition site agreed with each other and both disagreed with `predict`. Adding the fields only to `router.ts`'s interface without wiring them would have type-checked too, so the tests assert the hooks actually fire rather than that the option is accepted. - **Both directions of `hooksRaise`.** The router raises by default, so a per-call `false` is only observable if a throwing hook is swallowed instead of failing the call — and a per-call `true` on a quiet router must start raising. Asserting one direction would pass with the override ignored in the other. - **Order is pinned, not just membership.** A per-call `onPredictStart` must run *after* a per-call `hooks` entry, which is the composition `predict` uses; asserting only that both ran would accept either order. - **`predictMany` is covered separately** even though it forwards, because that forwarding is exactly the property being claimed. ## Tests Five tests in `tests/router-batch.test.ts`, alongside the existing per-call `hooks` test: ``` honours per-call onPredictStart and onPredictEnd, not just hooks appends per-call callbacks after per-call hooks, the composition predict uses lets a per-call hooksRaise override the router-level flag lets a per-call hooksRaise turn raising on where the router has it off predictMany honours the same per-call callbacks, since it forwards to predictBatch ``` **Confirmed the tests catch the bug:** with only the batch composition reverted (leaving `predict` untouched), the file reports `5 failed | 20 passed`, and every failure is one of the five new tests. ``` laya-ts: node node_modules/vitest/vitest.mjs run 34 files passed, 634 tests passed (629 before; 5 new) tsc -p tsconfig.json --noEmit reports 3 error lines with and without this change -- all Cannot find module 'node:path' / Cannot find name 'process' in providers.ts, router.ts and tokenizer.ts, because @types/node is not installed here ``` Known limitation: the two `hooksRaise` tests deliberately make a hook throw, so the suite prints `laya: hook Object.onPredictEnd failed: Error: hook blew up` to stderr twice. That line is the swallowed failure being asserted, not a test error — the run exits 0.
|
Closing this one, and I want to be clear that it is not because of anything wrong with it. #936 fixes #935 and landed, and your production change and its are the same two lines. What decided it between them: #936 also forwards Your tests are better, though, and two of them cover ground #936 does not:
I would take both as a test-only follow-up against Two other things in here worth keeping on the record. Noting that this went unnoticed because the options interface and the composition site agreed with each other and both disagreed with |
NandhaKishorM#943 raised two checks that NandhaKishorM#936 does not make, and both were kept on the record when it was closed in its favour. Neither is in `router-batch.test.ts` today: - the `true` direction of the per-call `hooksRaise` override, asserting the override is honoured when the router has raising off, rather than only that the `false` direction is; - the order of a per-call `onPredictStart` against a per-call `hooks` entry, which fails on a swapped `composeHooks` argument where a membership check passes either way. Test-only: no production code changes. The casts NandhaKishorM#943 carried are dropped, since NandhaKishorM#936 widened `PredictBatchOptions` and the callbacks are typed now.
What this fixes
The batch path composed only part of the per-call hook surface, and type-checked while doing it:
So a per-call
onPredictStartoronPredictEndpassed topredictBatchwas silentlydropped — no hook, no error — and a per-call
hooksRaise: falsehad no effect.predictManyforwarded
optsfaithfully and so inherited the same gap. Reported in #935.The Python side of the same asymmetry was closed in #912, which is what makes this a mirror rather
than a redesign.
The fix
PredictBatchOptionsgains the three fields, and the batch dispatch site composes them the waypredictdoes — per-call callbacks after per-callhooks, both after the installed ones — withhooksRaiseoverriding the router-level flag for that call only.Deliberate choices tested:
predict. Adding the fields to the interface without wiring them would type-check too, so the tests assert the hooks actually fire rather than that the option is accepted.hooksRaise. The router raises by default, so a per-callfalseis only observable if a throwing hook is swallowed instead of failing the call — and a per-calltrueon a quiet router must start raising. One direction would pass with the override ignored in the other.onPredictStartmust run after a per-callhooksentry; asserting only that both ran would accept either order.predictManycovered separately, because that forwarding is exactly the property being claimed.Tests
Five tests in
tests/router-batch.test.ts, alongside the existing per-callhookstest.Confirmed they catch the bug — with only the batch composition reverted (
predictuntouched),the file reports
5 failed | 20 passedand every failure is one of the five new tests.Known limitation: the two
hooksRaisetests deliberately make a hook throw, so the suite printslaya: hook Object.onPredictEnd failed: Error: hook blew upto stderr twice. That is theswallowed failure being asserted, not a test error — the run exits 0.